import numpy as np
import pyqtgraph as pg
from PyQt5.QtWidgets import QWidget


class WaveGraph(QWidget):
    """
    单次雷达数据波投射到二维坐标上的UI
    """
    def __init__(self):
        super().__init__()
        pg.setConfigOptions(antialias=True)
        self.resize(400, 500)
        self.pw = pg.PlotWidget(self)
        self.pw.resize(380, 480)
        self.curve = self.pw.plot(pen='y')
        self.curve.getViewBox().invertY(True)
        self.pw.setXRange(-500, 500, padding=0.1)

    def init_args(self, dataAir):
        self.curve.setData([], [])
        self.dataAir = dataAir.real * 10000
        self.dataAir = np.mean(self.dataAir.real.T, 1)

    def handle_data(self, data, t):
        """
        将data投射到当前坐标里
        :param t: 时间轴
        :param data: 最新的单次雷达数据
        :return:
        """

        self.curve.setData(data-self.dataAir, t)
